package caiziyou.com.designpattern.principle.demeter;

import java.util.ArrayList;
import java.util.List;

/**
 * 迪米特法则，最小知道法则，A类依赖B类，降低耦合 陌生的类最好不要以局部变量的形式出现
 * 
 * @author Administrator
 *
 */
public class DemeterDemo {

	public static void main(String[] args) {
		SchoolManager schoolManager = new SchoolManager();
		schoolManager.printAllEmployee(new CollegeManager());
	}
}

//学校总部员工
class Employee {
	private String id;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

}

//学院员工
class College {
	private String id;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

}

class CollegeManager {
	public List<College> getColleges() {
		ArrayList<College> arrayList = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			College college = new College();
			college.setId(String.valueOf(i));
			arrayList.add(college);
		}
		return arrayList;
	}
}

class SchoolManager {
	public List<Employee> getEmployees() {
		ArrayList<Employee> arrayList = new ArrayList<>();
		for (int i = 0; i < 5; i++) {
			Employee college = new Employee();
			college.setId(String.valueOf(i));
			arrayList.add(college);
		}
		return arrayList;
	}

	void printAllEmployee(CollegeManager c) {
		System.out.println("---------------学院员工---------------------");
		List<College> colleges = c.getColleges();
		for (int i = 0; i < colleges.size(); i++) {
			System.out.println("学院员工Id" + colleges.get(i).getId());
		}
		System.out.println("---------------学校员工---------------------");
		List<Employee> employees = this.getEmployees();
		for (int i = 0; i < employees.size(); i++) {
			System.out.println("学校员工Id" + employees.get(i).getId());
		}
	}
}
